﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TpBaseObjects.Models;
using TpBaseObjects.Objects;
using TpData.Layer;
using TpExtensions;

namespace TpData.Manager {

    public class CashSaleDataManager {

        #region Members

        private static List<CashSaleModel> cashSales;

        #endregion

        #region Load

        public static int GetCashSaleInvoiceNumber(int cashSaleID, int userID) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.GetCashSaleInvoiceNumber(cashSaleID, userID);
            }
        }

        public static CashSaleModel LoadCashSale(int cashSaleID) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.LoadCashSale(cashSaleID);
            }
        }

        public static List<CashSaleModel> LoadCashSales() {
            return LoadCashSales(false);
        }

        public static List<CashSaleModel> LoadCashSales(bool reload) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                if (cashSales == null || reload) {
                    cashSales = dl.LoadCashSales();
                }
                return cashSales;
            }
        }

        public static PaymentModeObj LoadPaymentType(int paymentID) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.LoadPaymentType(paymentID);
            }
        }

        public static List<PaymentModeObj> LoadPaymentModes() {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.LoadPaymentTypes();
            }
        }

        public static CashSaleProductsModel LoadProduct(int productID) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.LoadProduct(productID);
            }
        }

        #endregion

        #region Save

        public static bool SaveCashSale(CashSaleModel myModel) {
            using (CashSaleDataLayer dl = CreateCashSaleDataLayer()) {
                return dl.SaveCashSale(myModel);
            }
        }

        #endregion

        #region Methods

        public static void UpdateCache(List<CashSaleModel> model) {
            cashSales = model;
        }

        #endregion

        #region Functions

        private static CashSaleDataLayer CreateCashSaleDataLayer() {
            return (DataManager.CreateDataLayer(typeof(CashSaleDataLayer)) as CashSaleDataLayer);
        }

        #endregion

    }
}
